package com.dao;

import com.bean.Employee;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;


@Repository
public class EmployeeDao {

    private static Map<Integer, Employee> employees = null;

    static {
        employees = new HashMap<Integer,Employee>();

        employees.put(0001,new Employee(0001,"张三","123@123",22));
        employees.put(0002,new Employee(0002,"张三","123@123",22));
        employees.put(0003,new Employee(0003,"张三","123@123",22));
        employees.put(0004,new Employee(0004,"张三","123@123",22));
        employees.put(0005,new Employee(0005,"张三","123@123",22));


    }

    private  static int initId=0006;

    public void save(Employee employee){
//        if(employee.getId() == null){
//            employee.setId(initId++);
//        }
        employee.setId(initId);
        employees.put(employee.getId(),employee);
        initId++;
    }

    public Collection<Employee> getAll(){

        return employees.values();
    }

    public Employee get(int id){

        return employees.get(id);
    }

    public void delete(int id){

        employees.remove(id);
    }
}
